package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    /**
     * 根据名称模糊查询分页列表
     * @param channelDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes ="author:ssh")
    @ApiImplicitParam(name = "channelDto",value = "查询对象",required = true,dataType ="ChannelDto" )
    public ResponseResult listByName(@RequestBody ChannelDto channelDto){
        return iWmChannelService.listByName(channelDto);
    }

    /**
     * 频道新增
     * @param channel
     * @return
     */
    @PostMapping
    @ApiOperation(value = "频道新增",notes ="author:ssh" )
    @ApiImplicitParam(name = "channel",value = "频道新增对象",required = true,dataType = "WmChannel")
    public ResponseResult saveWmChannel(@RequestBody WmChannel channel){
        return iWmChannelService.saveWmChannel(channel);
    }

    /**
     * 频道管理:修改
     * @param wmChannel
     * @return
     */
    @PutMapping
    public  ResponseResult update(@RequestBody WmChannel wmChannel){
       return iWmChannelService.updateChannel(wmChannel);

    }

    /**
     * 频道管理:删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable(value = "id") Integer id){
        iWmChannelService.removeById(id);
        return ResponseResult.okResult();
    }

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = iWmChannelService.list();
        return ResponseResult.okResult(list);
    }

}
